//
//  SwitchGridCell.m
//  商城
//
//  Created by runone02 on 2018/9/17.
//  Copyright © 2018年 liqiyun. All rights reserved.
//

#import "SwitchGridCell.h"
#import "DCRecommendItem.h"
#import <UIImageView+WebCache.h>


@interface SwitchGridCell ()

/* 图片 */
@property (strong , nonatomic)UIImageView *gridImageView;
/** 名称*/
@property (nonatomic,strong) UILabel *nameLabel;
/** 时间*/
@property (nonatomic,strong) UILabel *timeLabel;
/** 类型*/
@property (nonatomic,strong) UIImageView *typeImage;
/** 桩号*/
@property (nonatomic,strong) UILabel *mileageLabel;
/** 图片*/
@property (nonatomic,strong) UIImageView *iconView;
/**观看人数*/
@property (nonatomic,strong) UILabel *peopleLabel;

@end

@implementation SwitchGridCell

#pragma mark - Intial
- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setUpUI];
    }
    return self;
}

#pragma mark - UI
- (void)setUpUI{
    UIView *bgView = [[UIView alloc]init];
    bgView.backgroundColor = [UIColor redColor];
    [self addSubview:bgView];
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.mas_equalTo(self);
    }];
    
    self.nameLabel = [[UILabel alloc]init];
    self.nameLabel.font = TITLE_FONT(28);
    self.nameLabel.textAlignment = NSTextAlignmentLeft;
    self.nameLabel.text = @"名字";
    self.nameLabel.textColor = [UIColor blackColor];
    [bgView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(bgView).with.offset(2);
        make.left.mas_equalTo(bgView).with.offset(5);
        make.width.mas_equalTo(SCREEN_WIDTH/4);
        make.height.mas_equalTo(15);
    }];
    
    self.timeLabel = [[UILabel alloc]init];
    self.timeLabel.font = TITLE_FONT(28);
    self.timeLabel.textAlignment = NSTextAlignmentRight;
    self.timeLabel.text = @"2018-9-18";
    self.timeLabel.textColor = [UIColor blackColor];
    [bgView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(bgView).with.offset(2);
        make.right.mas_equalTo(bgView).with.offset(-5);
        make.left.mas_equalTo(self.nameLabel.mas_right).with.offset(10);
        make.height.mas_equalTo(15);
    }];    
    
    self.typeImage = [[UIImageView alloc]init];
    self.typeImage.image = IMAGE(@"taozhuang_tag");
    [bgView addSubview:self.typeImage];
    [self.typeImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(bgView).with.offset(-2);
        make.left.mas_equalTo(bgView).with.offset(5);
        make.width.height.mas_equalTo(20);
    }];
    
    self.mileageLabel = [[UILabel alloc]init];
    self.mileageLabel.textAlignment = NSTextAlignmentRight;
    self.mileageLabel.font = TITLE_FONT(28);
    self.mileageLabel.textColor = [UIColor blackColor];
    [bgView addSubview:self.mileageLabel];
    
    [self.mileageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.typeImage);
        make.left.mas_equalTo(self.typeImage.mas_right).with.offset(5);
        make.right.mas_equalTo(bgView).with.offset(-5);
    }];    
    
    _gridImageView = [[UIImageView alloc] init];   //商品图片
    _gridImageView.contentMode = UIViewContentModeScaleAspectFill;
    _gridImageView.clipsToBounds = YES;
    [bgView addSubview:_gridImageView];
    
    [_gridImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.nameLabel.mas_bottom).with.offset(5);
        make.left.mas_equalTo(bgView).with.offset(5);
        make.right.mas_equalTo(bgView).with.offset(-5);
        make.bottom.mas_equalTo(self.typeImage.mas_top).with.offset(-5);
    }];
    
    self.peopleLabel = [[UILabel alloc]init];
    self.peopleLabel.textColor = [UIColor blackColor];
    self.peopleLabel.text = @"观看人数";
    self.peopleLabel.font = TITLE_FONT(24);
    [_gridImageView addSubview:self.peopleLabel];
    [self.peopleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.gridImageView).with.offset(-5);
        make.bottom.mas_equalTo(self.gridImageView).with.offset(-5);
    }];
    
    self.iconView = [[UIImageView alloc]init];
    self.iconView.backgroundColor = [UIColor blueColor];
    [self.gridImageView addSubview:self.iconView];
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.peopleLabel.mas_left).with.offset(-5);
        make.bottom.mas_equalTo(self.gridImageView).with.offset(-5);
        make.height.width.mas_equalTo(20);
    }];

}

#pragma mark - Setter Getter Methods
- (void)setYouSelectItem:(DCRecommendItem *)youSelectItem{
    _youSelectItem = youSelectItem;
    [_gridImageView sd_setImageWithURL:[NSURL URLWithString:youSelectItem.image_url]];
    _timeLabel.text = youSelectItem.goods_title;
    
    _nameLabel.text = youSelectItem.main_title;
    _mileageLabel.text = youSelectItem.stock;
}


@end
